<template>
  <div class="app-container">
    <el-card>
      <el-table :data="list">
        <el-table-column label="ID">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="业务类型" prop="businessName" />
        <el-table-column label="发起人" prop="creator" />
        <el-table-column label="备注" prop="message" />
        <el-table-column label="申请时间" prop="startDate">
          <template slot-scope="scope">
            {{ parseTime(scope.row.startDate) }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="showDetail(scope.row)"
            >详情</el-button>
            <el-button
              type="text"
              @click="handleAgree(scope.row.taskId)"
            >通过</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getMyTodo, agree } from '@/api/todo'

export default {
  name: 'MyTodo',
  data() {
    return {
      list: [],
      total: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getMyTodo().then((response) => {
        this.list = response.data.list
        this.total = response.data.total
      })
    },
    showDetail(row) {
      const value = JSON.parse(row.businessData)
      this.$router.push({
        path: '/oa/myTodo/detail',
        query: { taskId: row.taskId, value: value, path: row.path }
      })
    },
    handleAgree(taskId) {
      this.$confirm('是否通过申请', '审批')
        .then((s) => {
          agree(taskId).then((response) => {
            this.getList()
          })
        })
        .catch((e) => {})
    }
  }
}
</script>

<style>

</style>
